package com.qf.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.ssm.dto.ResultCode;
import com.qf.ssm.exceptions.AddErrorException;
import com.qf.ssm.exceptions.DeleteErrorException;
import com.qf.ssm.exceptions.UpdateErrorException;
import com.qf.ssm.mapper.RoleMenuMapper;
import com.qf.ssm.pojo.CheckStatus;
import com.qf.ssm.pojo.RoleMenu;
import com.qf.ssm.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class RoleMenuServiceImpl implements RoleMenuService {

    private RoleMenuMapper roleMenuMapper;

    @Autowired
    public void setRoleMenuMapper(RoleMenuMapper roleMenuMapper) {
        this.roleMenuMapper = roleMenuMapper;
    }

    @Override
    public void addRoleMenu(RoleMenu roleMenu) {
        boolean isNull = roleMenu.isNull(CheckStatus.ADD);
        if(isNull){
            throw new AddErrorException("数据不完整，请检查数据",ResultCode.DATA_NOT_ALLOW_NUL);
        }
        roleMenuMapper.addRoleMenu(roleMenu);
    }

    @Override
    public void updateRoleMenu(RoleMenu roleMenu) {
        if(roleMenu.isNull(CheckStatus.UPDATE)){
            throw new UpdateErrorException("更新数据为空", ResultCode.DATA_NOT_ALLOW_NUL);
        }
        roleMenuMapper.updateRoleMenu(roleMenu);
    }

    @Override
    public void deleteRoleMenuByIds(Long[] ids) {
        if(ids==null||ids.length==0){
            throw new DeleteErrorException("删除必须传递id",ResultCode.DATA_NOT_ALLOW_NUL);
        }
            roleMenuMapper.deleteRoleMenuByIds(Arrays.asList(ids));
    }

    @Override
    public List<RoleMenu> findAllRoleMenu() {
        return roleMenuMapper.findAllRoleMenu();
    }


}
